/*
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License. 
*/

package com.google.enterprise.gsa.crf;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.IdGeneratorStrategy;

/**
 * @author luiscamacho
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)

public class DBClickRecord implements JSONEnabled{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String date;
	@Persistent
	private String q;
	@Persistent
	private String ct;
	@Persistent
	private int r;
	@Persistent
	private String url;
	@Persistent
	private int start;
	
	public DBClickRecord(String date, String q, String ct, int r, String url, int start){
		this.date = date;
		this.q = q;
		this.ct = ct;
		this.r = r;
		this.url = url;
		this.start = start;
	}
	@SuppressWarnings("unused")
	private void setCt(String ct) {
		this.ct = ct;
	}
	public String getCt() {
		return ct;
	}
	@SuppressWarnings("unused")
	private void setDate(String date) {
		this.date = date;
	}
	public String getDate() {
		return date;
	}
	@SuppressWarnings("unused")
	private void setQ(String q) {
		this.q = q;
	}
	public String getQ() {
		return q;
	}
	@SuppressWarnings("unused")
	private void setR(int r) {
		this.r = r;
	}
	public int getR() {
		return r;
	}
	
	@SuppressWarnings("unused")
	private void setStart(int start) {
		this.start = start;
	}
	public int getStart() {
		return start;
	}
	
	@SuppressWarnings("unused")
	private void setUrl(String url) {
		this.url = url;
	}

	public String getUrl() {
		return url;
	}
	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}
	@SuppressWarnings("unused")
	private Long getId() {
		return id;
	}
	
	public final static String JSONColumns(){	
		String ret = "[{id: 'date', label: 'Date', type: 'string'},{id: 'q', label: 'Query', type: 'string'},{id: 'ct', label: 'ct', type: 'string'}";
		ret += ",{id: 'rank', label: 'Rank', type: 'number'},{id: 'url', label: 'URL', type: 'string'}]";
		return ret;
	}
	
	@Override
	public String toJSON() {
		int rank = r + start;
		String ret = "{c:[{v: '" + date.toString() + "'}, {v: '" + q + "'}, {v: '" + ct + "'}";
		ret += ", {v: " + rank + "}, {v: '" + url + "'}]}";
		return ret;
	}
}
